package com.xiaomage.view.draw3

import android.content.Context
import android.graphics.*
import android.view.View

/**
 * Created by Administrator on 2018/1/2.
 */
class RangeView(context: Context):View(context) {
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        //定义画笔
        val paint= Paint()
        paint.isAntiAlias=true
        paint.style=Paint.Style.STROKE
        paint.strokeWidth=5f
        paint.color= Color.parseColor("#448ced")

        val region=Region(10,10,100,100)
        drawRegion(canvas,region,paint)

        region.set(100,100,200,200)
        drawRegion(canvas,region,paint)

        //椭圆path
        val ovalPath=Path()
        val rectf=RectF(50f,50f,200f,500f)
        ovalPath.addOval(rectf,Path.Direction.CW)
        region.setPath(ovalPath,Region(50,50,200,200))

        drawRegion(canvas,region,paint)

    }
    fun drawRegion(canvas: Canvas,region: Region,paint: Paint){
        val regionIterator=RegionIterator(region)
        val rect=Rect()
        while (regionIterator.next(rect)){
            canvas.drawRect(rect,paint)
        }

    }
}